package mianshi.jingdong;

import java.math.BigInteger;
import java.util.Scanner;
import java.util.concurrent.locks.ReentrantLock;

public class R1 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        new ReentrantLock().lock();
        long n = scanner.nextInt();
        long x = scanner.nextInt();
        String s = "";
        s = scanner.next();

        long res = 0;
        for (int i = 0; i < n; i++) {
            if (s.charAt(i) == 'U') {
                res = (x / 2)%(long) Math.pow(10,18);
            } else if (s.charAt(i) == 'R') {
                res = (x * 2 + 1)%(long) Math.pow(10,18);
            } else if (s.charAt(i) == 'L') {
                res = (x * 2)%(long) Math.pow(10,18);
            }
            x = res;
        }

        System.out.println(res);


        BigInteger N = new BigInteger(scanner.next());
        BigInteger X = new BigInteger(scanner.next());
        String S = scanner.next();
        BigInteger r = new BigInteger("0");
        for (int i = 0; i < N.longValue(); i++) {
            if (S.charAt(i) == 'U') {
                r = X.divide(new BigInteger("2"));
            } else if (S.charAt(i) == 'R') {
                r = X.multiply(new BigInteger("2")).add(new BigInteger("1"));
            } else if (S.charAt(i) == 'L') {
                r = X.multiply(new BigInteger("2"));
            }
            X = r;
        }
        System.out.println(r);
    }
}

